﻿using System;
using System.Data;
using System.Drawing;
using System.Configuration;
using System.Collections.ObjectModel;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Linq;

namespace Gollie.Graph
{
	public class GraphDataSet
	{
		ValueCollection values = new ValueCollection();
		Color color = Color.Blue;
		string legend = " ";

		public GraphDataSet()
			: this(" ")
		{
		}

		public GraphDataSet(string legend)
			: this(legend, Color.Blue)
		{
		}

		public GraphDataSet(string legend, Color color)
		{
			this.legend = legend;
			this.color = color;
		}

		public ValueCollection ScaleToPercentage(double low, double high)
		{
			ValueCollection retVal = new ValueCollection();

			if (this.values.Count > 0)
			{
				double range = high - low;

				foreach (double value in this.values)
				{
					double scaledValue = range == 0 ? 0 : 100.0 * (value - low) / range;

					retVal.Add(scaledValue);
				}
			}

			return retVal;
		}

		public ValueCollection ScaleToPercentage()
		{
			ValueCollection retVal = new ValueCollection();

			if (this.values.Count == 0)
				return retVal;

			return this.ScaleToPercentage(this.values.LowerBound, this.values.UpperBound);
		}

		public ValueCollection Values
		{
			get { return this.values; }
		}

		public Color Color
		{
			get { return this.color; }
			set { this.color = value; }
		}

		public string Legend
		{
			get { return this.legend; }
			set { this.legend = value; }
		}
	}

	public class ValueCollection : Collection<double>
	{
		public double LowerBound { get { return this.Count == 0 ? 0 : this.Min(); } }
		public double UpperBound { get { return this.Count == 0 ? 0 : this.Max(); } }
	}
}